package com.terrier.ui.skins.skinBaseClasses
{
    import com.terrier.ui.skins.IWxCheckButtonSkin;
    import com.terrier.ui.skins.WxTextStyle;
    import com.terrier.ui.skins.WxFlaSkinUtility;

    import flash.display.DisplayObject;
    import flash.display.Sprite;

    public class WxCheckButtonSkinBase extends WxLabelButtonSkinBase implements IWxCheckButtonSkin
    {
        protected var _selectedUpBg:DisplayObject;

        protected var _selectedOverBg:DisplayObject;

        protected var _selectedDownBg:DisplayObject;

        protected var _selectedDisabledBg:DisplayObject;

        protected var _selectedUpTxtStyle:WxTextStyle;

        protected var _selectedOverTxtStyle:WxTextStyle;

        protected var _selectedDownTxtStyle:WxTextStyle;

        protected var _selectedDisabledTxtStyle:WxTextStyle;

        public function WxCheckButtonSkinBase()
        {
            super();
        }

        public function get selectedUpBg():DisplayObject
        {
            return _selectedUpBg;
        }

        public function get selectedOverBg():DisplayObject
        {
            return _selectedOverBg;
        }

        public function get selectedDownBg():DisplayObject
        {
            return _selectedDownBg;
        }

        public function get selectedDisabledBg():DisplayObject
        {
            return _selectedDisabledBg;
        }

        public function get selectedUpTxtStyle():WxTextStyle
        {
            return _selectedUpTxtStyle;
        }

        public function get selectedOverTxtStyle():WxTextStyle
        {
            return _selectedOverTxtStyle;
        }

        public function get selectedDownTxtStyle():WxTextStyle
        {
            return _selectedDownTxtStyle;
        }

        public function get selectedDisabledTxtStyle():WxTextStyle
        {
            return _selectedDisabledTxtStyle;
        }

        override public function set width(value:Number):void
        {
            super.width = value;
			
            _selectedUpBg != null ? _selectedUpBg.width = value : null;
            _selectedOverBg != null ? _selectedOverBg.width = value : null;
            _selectedDownBg != null ? _selectedDownBg.width = value : null;
            _selectedDisabledBg != null ? _selectedDisabledBg.width = value : null;
        }

        override public function set height(value:Number):void
        {
            super.height = value;
			
			_selectedUpBg != null ? _selectedUpBg.height = value : null;
			_selectedOverBg != null ? _selectedOverBg.height = value : null;
			_selectedDownBg != null ? _selectedDownBg.height = value : null;
			_selectedDisabledBg != null ? _selectedDisabledBg.height = value : null;
        }

        override public function initByAsset(asset:Sprite):void
        {
            super.initByAsset(asset);

            if (asset == null)
            {
                return;
            }

            if (asset.numChildren == 0)
            {
                return;
            }
            var bgAsset:Sprite = asset.getChildAt(0) as Sprite;
            _selectedUpBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 5);
            _selectedOverBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 6);
            _selectedDownBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 7);
            _selectedDisabledBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 8);

            if (asset.numChildren < 2)
            {
                return;
            }
            var textAsset:Sprite = asset.getChildAt(1) as Sprite;
            _selectedUpTxtStyle = WxFlaSkinUtility.getTextStyle(textAsset, 5);
            _selectedOverTxtStyle = WxFlaSkinUtility.getTextStyle(textAsset, 6);
            _selectedDownTxtStyle = WxFlaSkinUtility.getTextStyle(textAsset, 7);
            _selectedDisabledTxtStyle = WxFlaSkinUtility.getTextStyle(textAsset, 8);
        }
    }
}
